import CONSTANT from '@/common/constants.js';
import http from '@/common/http.js';
import Confirm from 'vux/src/components/confirm/index.vue';
import util from '@/common/util.js';

export default {
  name: 'schedule_stu_list',
  components: {Confirm},
  data () {
    return {
      siteId: '',
      // 班级id
      id: '',
      studentId: '',
      studentName: '',
      content: {},
      isDisabled:false,
      signClass:'signUpBtn',
      agree: true,
      show: false,
      classId: '',
      stuActiveClass: 'stuActive',
      isChooseAll: '全选',
      seq: 0,
      mainId: ''
    }
  },
  mounted () {
    this.classId = this.$route.query.classId
    this.seq = this.$route.query.seq
    this.mainId = this.$route.query.mainId
    let params = CONSTANT.NEWSIGNSTUDENTLIST + '?classId=' + this.classId + '&seq=' + this.seq
    http.get(params, {

    }, (res) => {
      console.log(JSON.stringify(res))
      this.content = res
      //this.mainId = this.content[0].mainId
      this.statusActiveConvert()
  })
  },
  methods: {
    statusActiveConvert() {
      for (var i = 0;i < this.content.length;i++) {
        if (this.content[i].statusName == '未上') {
          this.content[i].statusName = 'stuUnActive'
        } else if (this.content[i].statusName == '请假') {
          this.content[i].statusName = 'qj'
        } else if (this.content[i].statusName == '迟到') {
          this.content[i].statusName = 'cd'
        } else {
          this.content[i].statusName = 'stuActive'
        }
      }
    },
    signAdd() {
      http.post(CONSTANT.SIGNADD, {
        clazzId: this.classId,
        siteId: window.sessionStorage.getItem("siteId"),
        userId: window.sessionStorage.getItem("studentId")
      }, (res) => {
        console.log(res)
        this.content = res.studentList
        this.statusActiveConvert()
      })
    },
    signEdit(status) {
      let studentRecords = ''
      for (var i = 0;i < this.content.length;i++) {
          if (this.content[i].statusName == 'xz') {
            studentRecords += this.content[i].studentId + ',' + status + ';'
          }
      }
      if (studentRecords == '') {
          alert('请选中要修改的学生')
          return;
      }
      console.log(studentRecords)
      http.post(CONSTANT.SIGNEDIT, {
        clazzId: this.classId,
        siteId: window.sessionStorage.getItem("siteId"),
        userId: window.sessionStorage.getItem("studentId"),
        mainId: this.mainId,
        studentRecords:studentRecords
      }, (res) => {
        console.log(JSON.stringify(res))
        this.content = res
        this.statusActiveConvert()
        alert('提交成功')
    })
    },
    submit (status) {
      this.signEdit(status)
    },
    chooseAll (isChooseAll) {
      if (isChooseAll == '全选') {
        for (var i = 0;i < this.content.length;i++) {
          this.content[i].statusName = 'stuActive'
        }
        this.isChooseAll = '取消全选'
      } else {
        for (var i = 0;i < this.content.length;i++) {
          this.content[i].statusName = 'stuUnActive'
        }
        this.isChooseAll = '全选'
      }
    },
    stuClick (statusName,index) {
      if (statusName == 'xz') {
        this.content[index].statusName = 'stuUnActive'
      } else {
        this.content[index].statusName = 'xz'
      }
    },
    goStuListSchedule (classId,seq) {
      this.$router.push({path: '/schedule_stu_list',query:{'classId': classId,'seq' : seq}})
    },
    comeBack () {
      window.history.go(-1)
    },
    initList() {
      http.post(CONSTANT.SIGNCLASSSCHEDULE, {
        clazzId: _this.id
      }, (res) => {
        console.log(res)
      _this.content = res
      for (var i = 0;i < res.length;i++) {
        let dateStr = util.dateFormat(res[i].beginTime,true)
        let enddateStr = util.dateFormat(res[i].endTime,true)
        _this.content[i].beginTime = dateStr.substring(0,10)
        _this.content[i].endTime = dateStr.substring(11,16) + '到' + enddateStr.substring(11,16)
        _this.content[i].signIn.signNum = res[i].signIn.signNum + '/' + res[i].signIn.totalNum
      }
    })
    }
  }
}
